﻿namespace Home.Repository
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Home.Security.Authentication;

    internal static class SecurityDbHelper
    {
        public static readonly Guid UserWeiZhouId = new Guid("{797C7DBE-99F1-4A98-ABA4-5139F364A76D}");
        public static readonly Guid UserLvLeiYanId = new Guid("{4D868101-F0BC-4E68-B62E-B08C9DA01BC2}");
        public static readonly Guid UserJiYanQinId = new Guid("{3241DFC0-CAB2-41EE-8EA9-052C552D0B0A}");

        public const byte RoleSuperAdministrator = 1;
        public const byte RoleAdministrator = 2;
        public const byte RoleVisitor = 3;

        public const string IdentityProviderQQ = "Home Web Identity Provider QQ";
        public const string IdentityProviderSina = "Home Web Identity Provider Sina";
        public const string IdentityProviderWeChat = "Home Web Identity Provider WeChat";

        public static byte GetUserRole(Guid userId)
        {
            Debug.Assert(userId != Guid.Empty);

            if (userId == UserWeiZhouId)
            {
                return RoleSuperAdministrator;
            }

            if (userId == UserLvLeiYanId || userId == UserJiYanQinId)
            {
                return RoleAdministrator;
            }

            return RoleVisitor;
        }

        public static string GetIdentityProviderName(AuthenticationType type)
        {
            Debug.Assert(Enum.IsDefined(typeof(AuthenticationType), type));

            switch (type)
            {
                case AuthenticationType.QQ:
                    return IdentityProviderQQ;
                case AuthenticationType.Sina:
                    return IdentityProviderSina;
                case AuthenticationType.WeChat:
                    return IdentityProviderWeChat;
            }

            throw new NotImplementedException();
        }
    }
}
